<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品" prop="product">
        <el-input
          v-model="queryParams.product"
          placeholder="请输入产品"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线体" prop="line">
        <el-input
          v-model="queryParams.line"
          placeholder="请输入线体"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="站点" prop="station">
        <el-input
          v-model="queryParams.station"
          placeholder="请输入站点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组件名称" prop="mo">
        <el-input
          v-model="queryParams.mo"
          placeholder="请输入组件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机型的物料号" prop="mtm">
        <el-input
          v-model="queryParams.mtm"
          placeholder="请输入机型的物料号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务单号" prop="taskCode">
        <el-input
          v-model="queryParams.taskCode"
          placeholder="请输入任务单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机台号" prop="workbenchNo">
        <el-input
          v-model="queryParams.workbenchNo"
          placeholder="请输入机台号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="表单ID" prop="formId">
        <el-input
          v-model="queryParams.formId"
          placeholder="请输入表单ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分组ID(巡检ID/抽检ID/维修ID/过站ID)" prop="groupId">
        <el-input
          v-model="queryParams.groupId"
          placeholder="请输入分组ID(巡检ID/抽检ID/维修ID/过站ID)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="input_name值" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入input_name值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编号" prop="pn">
        <el-input
          v-model="queryParams.pn"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料类别" prop="pnClass">
        <el-input
          v-model="queryParams.pnClass"
          placeholder="请输入物料类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料的绑定数量" prop="pnQty">
        <el-input
          v-model="queryParams.pnQty"
          placeholder="请输入物料的绑定数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报废标记 0:正常 1:报废" prop="scrap">
        <el-input
          v-model="queryParams.scrap"
          placeholder="请输入报废标记 0:正常 1:报废"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="PASS/NG" prop="ngValue">
        <el-input
          v-model="queryParams.ngValue"
          placeholder="请输入PASS/NG"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="版本号" prop="version">
        <el-input
          v-model="queryParams.version"
          placeholder="请输入版本号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['demo:MesBindTaskData:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['demo:MesBindTaskData:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['demo:MesBindTaskData:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['demo:MesBindTaskData:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="MesBindTaskDataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="产品" align="center" prop="product" />
      <el-table-column label="线体" align="center" prop="line" />
      <el-table-column label="站点" align="center" prop="station" />
      <el-table-column label="组件名称" align="center" prop="mo" />
      <el-table-column label="机型的物料号" align="center" prop="mtm" />
      <el-table-column label="任务单号" align="center" prop="taskCode" />
      <el-table-column label="机台号" align="center" prop="workbenchNo" />
      <el-table-column label="表单ID" align="center" prop="formId" />
      <el-table-column label="表单类型：INPUT--扫描录入；CHECK--首件检验" align="center" prop="formType" />
      <el-table-column label="组件类型： input:text  input:radio  label" align="center" prop="type" />
      <el-table-column label="分组ID(巡检ID/抽检ID/维修ID/过站ID)" align="center" prop="groupId" />
      <el-table-column label="input_label值" align="center" prop="label" />
      <el-table-column label="input_name值" align="center" prop="name" />
      <el-table-column label="input_value值" align="center" prop="value" />
      <el-table-column label="物料编号" align="center" prop="pn" />
      <el-table-column label="物料类别" align="center" prop="pnClass" />
      <el-table-column label="物料的绑定数量" align="center" prop="pnQty" />
      <el-table-column label="报废标记 0:正常 1:报废" align="center" prop="scrap" />
      <el-table-column label="PASS/NG" align="center" prop="ngValue" />
      <el-table-column label="版本号" align="center" prop="version" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['demo:MesBindTaskData:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['demo:MesBindTaskData:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改任务单记录数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品" prop="product">
          <el-input v-model="form.product" placeholder="请输入产品" />
        </el-form-item>
        <el-form-item label="线体" prop="line">
          <el-input v-model="form.line" placeholder="请输入线体" />
        </el-form-item>
        <el-form-item label="站点" prop="station">
          <el-input v-model="form.station" placeholder="请输入站点" />
        </el-form-item>
        <el-form-item label="组件名称" prop="mo">
          <el-input v-model="form.mo" placeholder="请输入组件名称" />
        </el-form-item>
        <el-form-item label="机型的物料号" prop="mtm">
          <el-input v-model="form.mtm" placeholder="请输入机型的物料号" />
        </el-form-item>
        <el-form-item label="任务单号" prop="taskCode">
          <el-input v-model="form.taskCode" placeholder="请输入任务单号" />
        </el-form-item>
        <el-form-item label="机台号" prop="workbenchNo">
          <el-input v-model="form.workbenchNo" placeholder="请输入机台号" />
        </el-form-item>
        <el-form-item label="表单ID" prop="formId">
          <el-input v-model="form.formId" placeholder="请输入表单ID" />
        </el-form-item>
        <el-form-item label="分组ID(巡检ID/抽检ID/维修ID/过站ID)" prop="groupId">
          <el-input v-model="form.groupId" placeholder="请输入分组ID(巡检ID/抽检ID/维修ID/过站ID)" />
        </el-form-item>
        <el-form-item label="input_label值" prop="label">
          <el-input v-model="form.label" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="input_name值" prop="name">
          <el-input v-model="form.name" placeholder="请输入input_name值" />
        </el-form-item>
        <el-form-item label="input_value值" prop="value">
          <el-input v-model="form.value" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="物料编号" prop="pn">
          <el-input v-model="form.pn" placeholder="请输入物料编号" />
        </el-form-item>
        <el-form-item label="物料类别" prop="pnClass">
          <el-input v-model="form.pnClass" placeholder="请输入物料类别" />
        </el-form-item>
        <el-form-item label="物料的绑定数量" prop="pnQty">
          <el-input v-model="form.pnQty" placeholder="请输入物料的绑定数量" />
        </el-form-item>
        <el-form-item label="报废标记 0:正常 1:报废" prop="scrap">
          <el-input v-model="form.scrap" placeholder="请输入报废标记 0:正常 1:报废" />
        </el-form-item>
        <el-form-item label="PASS/NG" prop="ngValue">
          <el-input v-model="form.ngValue" placeholder="请输入PASS/NG" />
        </el-form-item>
        <el-form-item label="逻辑删除:  0:正常 1:已删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入逻辑删除:  0:正常 1:已删除" />
        </el-form-item>
        <el-form-item label="版本号" prop="version">
          <el-input v-model="form.version" placeholder="请输入版本号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMesBindTaskData, getMesBindTaskData, delMesBindTaskData, addMesBindTaskData, updateMesBindTaskData } from "@/api/demo/MesBindTaskData";

export default {
  name: "MesBindTaskData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务单记录数据表格数据
      MesBindTaskDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        product: null,
        line: null,
        station: null,
        mo: null,
        mtm: null,
        taskCode: null,
        workbenchNo: null,
        formId: null,
        formType: null,
        type: null,
        groupId: null,
        label: null,
        name: null,
        value: null,
        pn: null,
        pnClass: null,
        pnQty: null,
        scrap: null,
        ngValue: null,
        version: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        station: [
          { required: true, message: "站点不能为空", trigger: "blur" }
        ],
        taskCode: [
          { required: true, message: "任务单号不能为空", trigger: "blur" }
        ],
        pn: [
          { required: true, message: "物料编号不能为空", trigger: "blur" }
        ],
        pnClass: [
          { required: true, message: "物料类别不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询任务单记录数据列表 */
    getList() {
      this.loading = true;
      listMesBindTaskData(this.queryParams).then(response => {
        this.MesBindTaskDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        product: null,
        line: null,
        station: null,
        mo: null,
        mtm: null,
        taskCode: null,
        workbenchNo: null,
        formId: null,
        formType: null,
        type: null,
        groupId: null,
        label: null,
        name: null,
        value: null,
        pn: null,
        pnClass: null,
        pnQty: null,
        scrap: null,
        ngValue: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        version: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加任务单记录数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMesBindTaskData(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改任务单记录数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMesBindTaskData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMesBindTaskData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除任务单记录数据编号为"' + ids + '"的数据项？').then(function() {
        return delMesBindTaskData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('demo/MesBindTaskData/export', {
        ...this.queryParams
      }, `MesBindTaskData_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
